# 元素定位
# 1. 个人
from selenium.webdriver.common.by import By

from base.page_base import PageBase


class AddSite(PageBase):
    # 个人
    __mine = (By.XPATH, '//android.widget.TextView[@text="个人"]')
    # 2. 设置
    __setting = (By.ID, 'com.netease.yanxuan:id/ivSetting')
    # 3. 我的地址
    __address = (By.XPATH, '//android.widget.TextView[@text="我的地址"]')
    # 4. 新增地址
    __add_address = (By.XPATH, '//android.widget.TextView[@text="新建地址"]')
    # 5. 下拉选中省份、市、县
    __province = (By.XPATH, '//android.widget.TextView[@text="北京市"]')
    __city = (By.XPATH, '//android.widget.TextView[@text="顺义区"]')
    __county = (By.XPATH, '//android.widget.TextView[@text="马坡地区"]')
    # 6.确定
    __confirm = (By.ID, 'com.netease.yanxuan:id/btn_confirm_address_manage')
    # 7.详细地址
    __detail_address = (By.ID, 'com.netease.yanxuan:id/address_detial_edit')
    # 8.姓名
    __name = (By.ID, 'com.netease.yanxuan:id/address_name_edit')
    # 9.手机号
    __phone = (By.ID, 'com.netease.yanxuan:id/address_phonenumber_edit')
    # 10.保存
    __save = (By.ID, 'com.netease.yanxuan:id/nav_right_text')
    # 11.获取文本
    __get_text = (By.XPATH, '(//android.widget.TextView[@text="李国伟"])[1]')


    #定义方法
    def click_mine(self):
        """选择个人"""
        self.base_click(self.__mine)

    def click_setting(self):
        """选择设置"""
        self.base_click(self.__setting)

    def click_address(self):
        """选择我的地址"""
        self.base_click(self.__address)
    def click_add_address(self):
        """选择城市"""
        self.base_click(self.__add_address)

    def click_add_province(self):
        """选择省份"""
        self.base_click(self.__province)

    def click_add_city(self,x1, y1,x=540, y=1800):
        """选择市,"""
        self.base_swipe(x, y, x1, y1,1000)
        self.base_click(self.__city)

    def click_province(self,x2,y2,x=540, y=1800):
        """选择区"""
        self.base_swipe(x, y, x2, y2,1000)
        self.base_click(self.__county)

        self.base_click(self.__confirm)

    def input_detail_address(self,text,name,phone):
        """输入详细地址"""
        self.base_input_text(self.__detail_address,text)

        self.base_input_text(self.__name,name)
        self.base_input_text(self.__phone,phone)
        self.base_click(self.__save)

    def add_site(self):
        """新增地址业务流程"""
        self.click_mine()
        self.click_setting()
        self.click_address()
        self.click_add_address()
        self.click_add_province()

    def click_get_text(self):
        """获取文本"""
        return self.base_get_text(self.__get_text)






